package com.yanxml.spring.history.v3.demo7_deferred_import_selector.deferred_import_selector;

import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.List;

public class MyDeferredImportSelector2 implements DeferredImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        System.out.println("MyDeferredImportSelector -----------");
        return new String[0];
    }

    /**
     * 如果返回为null, 则执行父类中的selectImports方法.
     * 否则执行内部类Group中的方法
     *
     * */
    @Override
    public Class<? extends Group> getImportGroup() {
        System.out.println("getImportGroup -----------");
        return DeferredImportSelector.super.getImportGroup();
    }

    public static class MyGroup implements Group {

        List<Entry> entryList = new ArrayList<>();

        @Override
        public void process(AnnotationMetadata metadata, DeferredImportSelector selector) {
            System.out.println("MyGroup --- > process");
        }

        @Override
        public Iterable<Entry> selectImports() {
            System.out.println("MyGroup --- > selectImports");
            return entryList;
        }
    }
}
